package com.hongji.wiki.controller;
import com.hongji.wiki.req.EbookQueryReq;
import com.hongji.wiki.req.EbookSaveReq;
import com.hongji.wiki.resp.CommonResp;
import com.hongji.wiki.resp.EbookQueryResp;
import com.hongji.wiki.resp.PageResp;
import com.hongji.wiki.service.EbookService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ebook")
public class EbookController {

    @Resource
    private EbookService ebookService;

    @GetMapping("/list")
    public CommonResp list(@Valid EbookQueryReq req){

        CommonResp<PageResp<EbookQueryResp>> resp =new CommonResp<>();

        PageResp<EbookQueryResp> list =ebookService.list(req);

        resp.setContent(list);
        return  resp;
    }
@PostMapping("/save")
public CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp =new CommonResp();
        ebookService.save(req);
        return  resp;
}
@DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp resp =new CommonResp<>();
        ebookService.delete(id);
        return  resp;
}
}
